package com.salmon.study.fail;


import akka.actor.AbstractActor;
import akka.actor.ActorRef;
import akka.actor.Props;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class SupervisingActor extends AbstractActor {

    ActorRef child = getContext().actorOf(Props.create(SupervisedActor.class), "supervised-actor");


    @Override
    public void preStart() {
        System.out.println("SupervisingActor actor started");
    }

    @Override
    public void postStop() {
        log.info("{}",sender());
        System.out.println("SupervisingActor actor stopped");
    }

    @Override
    public Receive createReceive() {
        return receiveBuilder()
                .matchEquals("failChild", f -> {
                    log.info("{}", self());
                    child.tell("fail", self());
                }).build();
    }
}
